<?php
/**
 * BootAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using BootAdmin.
 *
 * @Author G.r<root@BootAdmin.com>
 */

declare (strict_types=1);

namespace app\common\logic;

use app\common\traits\JumpTrait;

/**
 * 逻辑基类
 */
class BaseLogic
{
    use JumpTrait;

    /**
     * 错误信息
     * @var string
     */
    protected string $error;

    /**
     * 返回状态码
     * @var int
     */
    protected int $returnCode = 400;

    /**
     * 返回数据
     * @var mixed
     */
    protected mixed $returnData;

    /**
     * 获取错误信息
     * @return string
     */
    public function getError() : string
    {
        if (false === $this->hasError()) {
            return '系统错误';
        }
        return $this->error;
    }


    /**
     * 设置错误信息
     * @param $error
     */
    public function setError($error) : void
    {
        !empty($error) && $this->error = $error;
    }


    /**
     * 是否存在错误
     * @return bool
     */
    public function hasError() : bool
    {
        return !empty($this->error);
    }


    /**
     * 设置状态码
     * @param $code
     */
    public function setReturnCode($code) : void
    {
        $this->returnCode = $code;
    }


    /**
     * 特殊场景返回指定状态码,默认为400
     * @return int
     */
    public function getReturnCode() : int
    {
        return $this->returnCode;
    }

    /**
     * 获取内容
     * @return mixed
     */
    public function getReturnData(): mixed
    {
        return $this->returnData;
    }
}